home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / buttonbase / source / buttonbase.e next >
Encoding:
Text File  |  1998-06-05  |  5.1 KB  |  140 lines

  1. /*
  2.    Name:        buttonbase.e
  3.    About:       A base Plugin for use with my custom BOOPSI button gadget
  4.    Version:     1.0 (5.6.98)
  5.    Author:      Copyright © 1998 Victor Ducedre (victord@netrover.com)
  6.  
  7.    A brief note:  This plugin is not meant to be used directly within your
  8.    EasyGUI-based program.  It is only a base class for subclasses, which only
  9.    handles the elements common to all sub classes.  Please see newbutton.e and
  10.    newimagebutton.e for examples of subclasses.
  11.  
  12. */
  13. OPT MODULE
  14. OPT PREPROCESS
  15. OPT OSVERSION=37
  16.  
  17. MODULE 'tools/EasyGUI', 'tools/textlen', 'graphics/rastport',
  18.        'intuition/intuition', 'intuition/gadgetclass', 'intuition/imageclass',
  19.        'gadgets/buttonclass', 'tools/ctype', 'utility', 'utility/tagitem'
  20.  
  21. CONST NB_GADGET=$FF010001   -> kept private, and defined in each subclass
  22.  
  23. EXPORT ENUM NB_SELECTED=$FF010002,       -> [ISG]
  24.   NB_RESIZEX,                            -> [I..]
  25.   NB_RESIZEY,                            -> [I..]
  26.   NB_TOGGLE,                             -> [I..]
  27.   NB_PUSH,                               -> [I..]
  28.   NB_DISABLED,                           -> [ISG]
  29.   NB_FRAMETYPE                           -> [I..]
  30.  
  31. EXPORT OBJECT buttonbase OF plugin PRIVATE
  32.   selected
  33.   disabled
  34.   gadget:PTR TO gadget
  35.   class
  36.   resize
  37.   toggle
  38.   push
  39.   frame
  40.   tags
  41. ENDOBJECT
  42.  
  43. PROC button(tags=NIL) OF buttonbase
  44.   IF utilitybase
  45.     self.class:=     initButtonGadgetClass()
  46.     IF self.class=NIL THEN Raise("nbut")
  47.     self.resize:=(IF GetTagData(NB_RESIZEX,   FALSE, tags) THEN RESIZEX ELSE 0) OR
  48.                  (IF GetTagData(NB_RESIZEY,   FALSE, tags) THEN RESIZEY ELSE 0)
  49.     self.toggle:=    GetTagData(NB_TOGGLE,    FALSE, tags)
  50.     self.push:=   IF self.toggle THEN FALSE ELSE GetTagData(NB_PUSH, FALSE, tags)
  51.     IF (self.toggle) OR (self.push) THEN
  52.       self.selected:=GetTagData(NB_SELECTED,  FALSE, tags)
  53.     self.disabled:=  GetTagData(NB_DISABLED,  FALSE, tags)
  54.     self.frame:=     GetTagData(NB_FRAMETYPE, BATT_BUTTONFRAME, tags)
  55.     self.tags:=      NIL
  56.   ELSE
  57.     Raise("util")
  58.   ENDIF
  59. ENDPROC
  60.  
  61. PROC end() OF buttonbase
  62. DEF tags
  63.   IF tags:=self.tags THEN END tags
  64.   IF self.class THEN freeButtonGadgetClass(self.class)
  65. ENDPROC
  66.  
  67. PROC will_resize() OF buttonbase IS self.resize
  68.  
  69. ->min_size() -subclasses only
  70.  
  71. PROC render(ta,x,y,xs,ys,w) OF buttonbase
  72.   self.gadget:=NewObjectA(self.class,NIL,
  73.                          [GA_TOP,y, GA_LEFT,x, GA_WIDTH,xs, GA_HEIGHT,ys,
  74.                           GA_TOGGLESELECT, self.toggle, BUT_PUSH, self.push,
  75.                           GA_DISABLED,self.disabled, GA_SELECTED,self.selected,
  76.                           BUT_FRAMETYPE, self.frame,
  77.                           GA_RELVERIFY,TRUE, TAG_MORE, self.tags, NIL])
  78.   IF self.gadget=NIL THEN Raise("nbut")
  79.   AddGList(w,self.gadget,-1,1,NIL)
  80.   RefreshGList(self.gadget,w,NIL,1)
  81. ENDPROC
  82.  
  83. PROC clear_render(win:PTR TO window) OF buttonbase
  84. DEF tags
  85.   IF tags:=self.tags THEN END tags
  86.   IF self.gadget
  87.     RemoveGList(win,self.gadget,1)
  88.     DisposeObject(self.gadget)
  89.   ENDIF
  90. ENDPROC
  91.  
  92. ->message_test()   -subclasses only
  93. ->message_action() -subclasses only
  94.  
  95. PROC set(attr, val) OF buttonbase
  96.   SELECT attr
  97.     CASE NB_GADGET  -> this attribute should only be sent by subclasses, not
  98.                     -> by the user of the plugin; NB_GADGET is kept private for
  99.                     -> this reason. 'val' should be a tag list to be sent
  100.                     -> directly to the gadget, and no checking is done on it.
  101.                     -> It's perhaps a bit of a kludge but does allows a cleaner,
  102.                     -> more consistent way for subclasses to alter their own
  103.                     -> gadget attributes.
  104.       IF visible(self) THEN SetGadgetAttrsA(self.gadget,self.gh.wnd,NIL,val)
  105.     CASE NB_DISABLED
  106.       IF self.disabled<>val
  107.         self.disabled:=val
  108.         IF visible(self) THEN
  109.           SetGadgetAttrsA(self.gadget,self.gh.wnd,NIL,[GA_DISABLED,val,NIL])
  110.       ENDIF
  111.     CASE NB_SELECTED
  112.       self.selected:=val
  113.       IF ((self.toggle) OR (self.push)) AND visible(self) THEN
  114.         SetGadgetAttrsA(self.gadget,self.gh.wnd,NIL,[GA_SELECTED,val,NIL])
  115.   ENDSELECT
  116. ENDPROC
  117.  
  118. PROC get(attr) OF buttonbase
  119.   SELECT attr
  120.     CASE NB_GADGET      -> this will return the pointer to the actual gadget
  121.                         -> for subclasses, but as far as any outside programs
  122.                         -> are concerned, as the second return value is FALSE,
  123.                         -> this attribute is not "get-able"
  124.                         RETURN self.gadget,   FALSE
  125.     CASE NB_SELECTED;   RETURN self.selected, TRUE
  126.     CASE NB_DISABLED;   RETURN self.disabled, TRUE
  127.   ENDSELECT
  128. ENDPROC -1, FALSE
  129.  
  130. PROC settags(tags) OF buttonbase
  131. -> This method exists only to maintain the privacy if the elements of the base
  132. -> object.  It allows subclasses to pass a tag list to self.tags, which is
  133. -> appended to the tag list sent to NewObjectA() in the render() method.
  134. ->    The tag list passed should be a dynamically created one (with NEW), the
  135. -> list is properly deallocated in clear_render() and in end()
  136.   self.tags:= IF tags THEN tags ELSE NEW [NIL]
  137. ENDPROC
  138.  
  139. PROC visible(self:PTR TO buttonbase) IS (self.gadget AND self.gh.wnd)
  140.